package ms.unicorn.ui.decorators;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.RotatableDecoration;
import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;

import ms.unicorn.modellanguage.DecoratorProxy;

public abstract class ConnectorDecorator implements IDecorator {

	public ConnectorDecorator() {
		super();
	}

	@Override
	public void createDecoration(IFigure target, DecoratorProxy config) {
		if (target instanceof PolylineConnectionEx) {
			PolylineConnectionEx connector = (PolylineConnectionEx) target;
			String location = config.getConstraint();
			RotatableDecoration decoration = createDecoration(config);
			if ("source".equalsIgnoreCase(location))
				connector.setSourceDecoration(decoration);
			else if ("target".equalsIgnoreCase(location))
				connector.setTargetDecoration(decoration);
		}
	}

	protected abstract RotatableDecoration createDecoration(DecoratorProxy config);

}